/*
 * @Description:
 * @Author: dh
 * @Date: 2021-09-24 14:32:08
 * @LastEditors: dh
 * @LastEditTime: 2024-05-14 14:48:07
 */

// TODO 基础类型
var n: number = 10
var s: string = '10'
var b: boolean = true
var S: symbol = Symbol('123')

// TODO 对象
// type O = { name: string; cb2(): void };
type O = { name: string; cb2: () => void }
var o1: O = { name: '', cb2: () => {} }
// FIXME 这里有点问题，缺失cb2也没报错
var o2 = <O>{ name: '' }

// TODO 数组
var arr1: number[] = [1, 2, 3]
var arr2: Array<number> = [1, 2, 3]
var arr3 = <Array<number>>[1, 2, 3]
var arr4: [number, string] = [1, '2']

// TODO Set
var set: Set<number> = new Set([1, 2])

// TODO Map
var mapKey = {}
var map: Map<any, any> = new Map()
map.set(mapKey, 1)

// FIXME 伪类
interface A {
	callee: Function
	length: number
	[index: number]: any
}
var arr5 = function (...args: any) {
	var a: IArguments = arguments
	var b: A = arguments
}

// TODO 元祖
var ls: [string, number] = ['1', 1]

// TODO null undefined 是所有类型的子类 ??? 但是要配置 strictNullChecks = false ，默认是true ，开启严格匹配模式，所以这里抛红
n = null
s = undefined

// TODO 函数
var fun0 = function <T>(name: string, age: T): void {}
function func1<T>(name: string, age: T): void {}

// TODO type 声明函数
type tyypeFunc = <T>(name: string, age: T) => void
type tyypeFunc2 = {
	// 存在函数重载时，这种方式不可用
	<T>(name: string, age: T): void
}
var func2: tyypeFunc = function (name, age) {}
var func3: tyypeFunc2 = function (name, age) {}

// TODO interface 声明函数
interface interfaceFunc {
	<T>(name: string, age: T): void
}
var func30: interfaceFunc = function (name, age) {}

// TODO 元素 节点类型
let node_div: HTMLDivElement = document.createElement('div')
let node_span: HTMLSpanElement = document.createElement('span')
let any_Node: HTMLElement = document.createElement('i')
type nodeType = typeof node_div

//TODO NodeList 范围比较广
let Div1: NodeList = document.querySelectorAll('div')
//TODO NodeListOf<【】> 指定的元素类型集合
let Div2: NodeListOf<HTMLDivElement> = document.querySelectorAll('div')
let Div3: NodeListOf<HTMLDivElement | Element> = document.querySelectorAll('div')

// TODO 事件源类型
document.addEventListener('click', (e: Event) => {})
document.addEventListener('touchstart', (e: TouchEvent) => {})

// TODO promise
var P: Promise<number> = new Promise((resolve, reject) => {
	resolve(2)
})
var P = new Promise<number>((resolve, reject) => {
	resolve(1)
})

const local: Storage = localStorage
const lo: Location = location
